package cn.kgc.service;

import cn.kgc.dao.CategoryDao;
import cn.kgc.dao.CategoryDaoImpl;
import cn.kgc.pojo.Category;
import cn.kgc.util.DataBaseUtil_single;
import cn.kgc.util.DatabaseUtil;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class CategoryServiceImpl implements  CategoryServcie {

    CategoryDao categoryDao=new CategoryDaoImpl();

    @Override
    public Category getCategoryById(Integer id) {
       Connection connection= DataBaseUtil_single.getInstance().getConnect();
       Category category= categoryDao.selectCategoryById(connection,id);
        DatabaseUtil.closeResult(connection,null,null);
        return category;
    }

    @Override
    public List<Category> getCategoryList() {
        Connection connection= DataBaseUtil_single.getInstance().getConnect();
        List<Category> list = null;
        try {
          list= categoryDao.selectCategory(connection);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        DatabaseUtil.closeResult(connection,null,null);
        return list;
    }
}
